//
//  FDMSearchTableViewCellSectionTwo.m
//  Entertainment
//
//  Created by dllo on 16/4/27.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMSearchTableViewCellSectionTwo.h"
#import "FDMSearchTracksModel.h"

@interface FDMSearchTableViewCellSectionTwo ()

@property (nonatomic, retain) UIImageView *titleImage;
@property (nonatomic, retain) FDMBaseButton *playButton;
@property (nonatomic, retain) FDMBaseLabel *titleLabel;
@property (nonatomic, retain) FDMBaseLabel *subTitleLabel;
@property (nonatomic, retain) FDMBaseLabel *playCountLabel;
@property (nonatomic, retain) FDMBaseLabel *likeCountLabel;
@property (nonatomic, retain) FDMBaseButton *downLoadButton;

@end
@implementation FDMSearchTableViewCellSectionTwo

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)createCell {
    self.titleImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleImage];
    [self.titleImage release];
    self.playButton = [FDMBaseButton buttonWithType:UIButtonTypeCustom];
    [self.titleImage addSubview:self.playButton];
    self.titleLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel release];
    self.subTitleLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.subTitleLabel];
    [self.subTitleLabel release];
    self.playCountLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.playCountLabel];
    [self.playCountLabel release];
    self.likeCountLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.likeCountLabel];
    [self.likeCountLabel release];
    self.downLoadButton = [FDMBaseButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.downLoadButton];

}

- (void)dealloc {
    [self.titleImage release];
    [self.playButton release];
    [self.titleLabel release];
    [self.subTitleLabel release];
    [self.playCountLabel release];
    [self.downLoadButton release];
    [self.likeCountLabel release];
    [super dealloc];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(10);
        make.left.equalTo(self.contentView.mas_left).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
        make.width.mas_equalTo(@80);
    }];
    self.playButton.layer.cornerRadius = 20;
    self.playButton.layer.masksToBounds = YES;
    [self.playButton setImage:[UIImage imageNamed:@"find_album_play@2x.png"] forState:UIControlStateNormal];
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleImage.mas_top).with.offset(20);
        make.left.equalTo(self.titleImage.mas_left).with.offset(20);
        make.bottom.equalTo(self.titleImage.mas_bottom).with.offset(- 20);
        make.right.equalTo(self.titleImage.mas_right).with.offset(-20);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(20);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_top).with.offset(30);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 110));
    }];
    self.subTitleLabel.font = [UIFont systemFontOfSize:14];
    self.subTitleLabel.textColor = [UIColor grayColor];
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(10);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.titleLabel.mas_bottom).with.offset(30);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 110));
    }];
    
    self.playCountLabel.font = [UIFont systemFontOfSize:14];
    self.playCountLabel.textColor = [UIColor grayColor];
    [self.playCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.subTitleLabel.mas_bottom).with.offset(10);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.subTitleLabel.mas_bottom).with.offset(20);
        make.width.mas_equalTo(@100);
    }];
    self.likeCountLabel.font = [UIFont systemFontOfSize:14];
    self.likeCountLabel.textColor = [UIColor grayColor];
    [self.likeCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.subTitleLabel.mas_bottom).with.offset(10);
        make.left.equalTo(self.playCountLabel.mas_right).with.offset(10);
        make.bottom.equalTo(self.subTitleLabel.mas_bottom).with.offset(20);
        make.width.mas_equalTo(150);
    }];
    [self.downLoadButton setImage:[UIImage imageNamed:@"me_more_download@2x.png"] forState:UIControlStateNormal];
    [self.downLoadButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_bottom).with.offset(- 50);
        make.left.equalTo(self.contentView.mas_right).with.offset(-60);
        make.right.equalTo(self.contentView.mas_right).with.offset(-10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(- 20);
    }];
    [self.playButton addTarget:self action:@selector(playButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.downLoadButton addTarget:self action:@selector(downLoadButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)playButtonAction:(FDMBaseButton *)button {
    [self.playButtonDelegate clickPlayButton];
}

- (void)downLoadButtonAction:(FDMBaseButton *)button {
    [self.downLoadDelegate clickDownLoadButton];
}

- (void)setModel:(FDMSearchTracksModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
        [self.titleImage sd_setImageWithURL:[NSURL URLWithString:_model.cover_path] placeholderImage:PLACEHOLDER_IMAGE];
        self.titleLabel.text = _model.title;
        self.subTitleLabel.text = _model.nickname;
        self.playCountLabel.text = [NSString stringWithFormat:@"播放次数：%@", _model.count_play];;
        self.likeCountLabel.text = [NSString stringWithFormat:@"喜欢：%@", _model.count_like];
        
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
